---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
      name:  <unnamed>
       log:  /Users/jesse/Dropbox/voter_id/Replication/table4.log
  log type:  text
 opened on:  17 Aug 2020, 11:41:31

. 
. use "$path/nc_dataset.dta" if new_reg == 0, clear

. 
. keep id election treat voted birth_year race_by_year age_by_year race_by_age_by_year ///
>         no_dmv_match race_string

. 
. // replace voted with NA if under 18 / ineligible in that election year 
. drop if birth_year > 1998 & birth_year < 9999
(84 observations deleted)

. replace voted = . if (birth_year > 1990 & birth_year < 9999) & (election == 1 | election == 2) // 2008
(1,102,090 real changes made, 1,102,090 to missing)

. replace voted = . if (birth_year > 1992 & birth_year < 9999) & (election == 3 | election == 4) // 2010
(680,176 real changes made, 680,176 to missing)

. replace voted = . if (birth_year > 1994 & birth_year < 9999) & (election == 5 | election == 6) // 2012
(269,954 real changes made, 269,954 to missing)

. replace voted = . if (birth_year > 1996 & birth_year < 9999) & (election == 7 | election == 8) // 2014
(314 real changes made, 314 to missing)

. 
. ** create string encoding of possible pre-treatment outcome paths
. tostring voted, generate(outcome_path)
outcome_path generated as str1

. 
. by id: gen outcome_path_pretreat = outcome_path[1] + outcome_path[2] + ///
>                                                                 outcome_path[3] + outcome_path[4] + ///
>                                                                 outcome_path[5] + outcome_path[6] + ///
>                                                                 outcome_path[7] + outcome_path[8] 

. 
. gen count = 1

. 
. // keep primary only
. keep if mod(election,2) == 1
(39,763,872 observations deleted)

. 
. replace voted = 0 if voted == .
(1,026,267 real changes made)

. 
. // construct age bins, give young voters who are ineligible for some election their own age bin
. gen age_bin = 11 if (birth_year > 1990 & birth_year < 9999)
(36,457,602 missing values generated)

. replace age_bin = 12 if (birth_year > 1992 & birth_year < 9999)
(2,040,528 real changes made)

. replace age_bin = 13 if (birth_year > 1994 & birth_year < 9999)
(809,862 real changes made)

. replace age_bin = 14 if (birth_year > 1996 & birth_year < 9999)
(942 real changes made)

. // give those who are eligible over the whole period their own age decile
. xtile age_decile = birth_year if (birth_year <= 1990), nq(10)

. replace age_bin = age_decile if (birth_year <= 1990)
(36,401,136 real changes made)

. drop age_decile

. 
. sort id election

. 
. gen treat_2018 = treat * (election == 11)

. 
. compress
  variable count was float now byte
  variable age_bin was float now byte
  variable treat_2018 was float now byte
  (357,874,848 bytes saved)

. 
. 
. * vanilla diff in diff
. reghdfe voted treat treat_2018, a(id election) cluster(id)
(converged in 3 iterations)

HDFE Linear regression                            Number of obs   = 39,763,872
Absorbing 2 HDFE groups                           F(   2,6627311) =    9363.63
Statistics robust to heteroskedasticity           Prob > F        =     0.0000
                                                  R-squared       =     0.5100
                                                  Adj R-squared   =     0.4120
                                                  Within R-sq.    =     0.0004
Number of clusters (id)      =  6,627,312         Root MSE        =     0.3204

                             (Std. Err. adjusted for 6,627,312 clusters in id)
------------------------------------------------------------------------------
             |               Robust
       voted |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
       treat |  -.0778748    .000709  -109.84   0.000    -.0792643   -.0764853
  treat_2018 |   .1020098   .0007559   134.96   0.000     .1005283    .1034912
------------------------------------------------------------------------------

Absorbed degrees of freedom:
---------------------------------------------------------------+
 Absorbed FE |  Num. Coefs.  =   Categories  -   Redundant     | 
-------------+-------------------------------------------------|
          id |            0         6627312        6627312 *   | 
    election |            5               6              1     | 
---------------------------------------------------------------+
* = fixed effect nested within cluster; treated as redundant for DoF computation

. local b1 = _b[treat]

. local se1 = _se[treat]

. local b1_2 = _b[treat_2018]

. local se1_2 = _se[treat_2018]

. local n1 = e(N)

. local nclust1 = e(N_clust)

. 
. * race by year
. reghdfe voted treat treat_2018, a(id race_by_year) cluster(id)
(converged in 3 iterations)

HDFE Linear regression                            Number of obs   = 39,763,872
Absorbing 2 HDFE groups                           F(   2,6627311) =    7001.46
Statistics robust to heteroskedasticity           Prob > F        =     0.0000
                                                  R-squared       =     0.5147
                                                  Adj R-squared   =     0.4176
                                                  Within R-sq.    =     0.0003
Number of clusters (id)      =  6,627,312         Root MSE        =     0.3188

                             (Std. Err. adjusted for 6,627,312 clusters in id)
------------------------------------------------------------------------------
             |               Robust
       voted |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
       treat |  -.0725412   .0007154  -101.40   0.000    -.0739434    -.071139
  treat_2018 |   .0870916   .0007616   114.36   0.000     .0855989    .0885843
------------------------------------------------------------------------------

Absorbed degrees of freedom:
---------------------------------------------------------------+
 Absorbed FE |  Num. Coefs.  =   Categories  -   Redundant     | 
-------------+-------------------------------------------------|
          id |            0         6627312        6627312 *   | 
race_by_year |           29              30              1     | 
---------------------------------------------------------------+
* = fixed effect nested within cluster; treated as redundant for DoF computation

. local b2 = _b[treat]

. local se2 = _se[treat]

. local b2_2 = _b[treat_2018]

. local se2_2 = _se[treat_2018]

. local n2 = e(N)

. local nclust2 = e(N_clust)

. 
. * age by year 
. reghdfe voted treat treat_2018, a(id age_by_year) cluster(id)
(converged in 3 iterations)

HDFE Linear regression                            Number of obs   = 39,707,406
Absorbing 2 HDFE groups                           F(   2,6617900) =    6538.02
Statistics robust to heteroskedasticity           Prob > F        =     0.0000
                                                  R-squared       =     0.5188
                                                  Adj R-squared   =     0.4225
                                                  Within R-sq.    =     0.0002
Number of clusters (id)      =  6,617,901         Root MSE        =     0.3176

                             (Std. Err. adjusted for 6,617,901 clusters in id)
------------------------------------------------------------------------------
             |               Robust
       voted |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
       treat |  -.0539785   .0007219   -74.78   0.000    -.0553934   -.0525637
  treat_2018 |   .0876779   .0007691   114.00   0.000     .0861705    .0891854
------------------------------------------------------------------------------

Absorbed degrees of freedom:
---------------------------------------------------------------+
 Absorbed FE |  Num. Coefs.  =   Categories  -   Redundant     | 
-------------+-------------------------------------------------|
          id |            0         6617901        6617901 *   | 
 age_by_year |          533             534              1     | 
---------------------------------------------------------------+
* = fixed effect nested within cluster; treated as redundant for DoF computation

. local b3 = _b[treat]

. local se3 = _se[treat]

. local b3_2 = _b[treat_2018]

. local se3_2 = _se[treat_2018]

. local n3 = e(N)

. local nclust3 = e(N_clust)

. 
. * age by race by year
. reghdfe voted treat treat_2018, a(id race_by_age_by_year) cluster(id)
(dropped 24 singleton observations)
(converged in 3 iterations)

HDFE Linear regression                            Number of obs   = 39,707,382
Absorbing 2 HDFE groups                           F(   2,6617896) =    5007.89
Statistics robust to heteroskedasticity           Prob > F        =     0.0000
                                                  R-squared       =     0.5240
                                                  Adj R-squared   =     0.4288
                                                  Within R-sq.    =     0.0002
Number of clusters (id)      =  6,617,897         Root MSE        =     0.3158

                             (Std. Err. adjusted for 6,617,897 clusters in id)
------------------------------------------------------------------------------
             |               Robust
       voted |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
       treat |  -.0477456   .0007285   -65.54   0.000    -.0491735   -.0463177
  treat_2018 |   .0774299   .0007761    99.77   0.000     .0759088    .0789509
------------------------------------------------------------------------------

Absorbed degrees of freedom:
----------------------------------------------------------------------+
        Absorbed FE |  Num. Coefs.  =   Categories  -   Redundant     | 
--------------------+-------------------------------------------------|
                 id |            0         6617897        6617897 *   | 
race_by_age_by_year |         2615            2616              1     | 
----------------------------------------------------------------------+
* = fixed effect nested within cluster; treated as redundant for DoF computation

. local b4 = _b[treat]

. local se4 = _se[treat]

. local b4_2 = _b[treat_2018]

. local se4_2 = _se[treat_2018]

. local n4 = e(N)

. local nclust4 = e(N_clust)

. 
. 
. // drop 2016 primary, just want difference in means in 2018 primary
. drop if election == 9 
(6,627,312 observations deleted)

. 
. preserve

. 
. collapse (sum) count (mean) voted, by(outcome_path_pretreat no_dmv_match election)

. 
. *** get N by path by summing together n treated and n control
. by outcome_path: gen tot_tmp = count[6] if _n==6
(2,941 missing values generated)

. egen tot_treat = sum(tot_tmp), by(outcome_path)

. by outcome_path: replace tot_tmp = count[1] if _n == 1
(341 real changes made)

. egen tot = sum(tot_tmp), by(outcome_path)

. // N_voters is the number of voters who enter into the regression
. egen N_voters = sum(tot_tmp)

. // get number of elections
. unique election
Number of unique values of election is  5
Number of records is  3250

. // N is number of voters * number of elections
. gen long N = N_voters * r(unique)

. drop tot_tmp

. gen tot_control = tot - tot_treat

. 
. *** get weights for fw based on total n per stratum
. *** each stratum has 10 obs
. *** fw requires integers so need to round
. gen tot2 = round(tot/10)

. gen tot_treat2 = round(tot_treat/10)

. egen op = group(outcome_path)

. 
. reghdfe voted no_dmv_match [fw=tot_treat2], a(op election)
weight tot_treat2 can only contain strictly positive integers, but 870 zero values were found (will be dropped)
(converged in 3 iterations)

HDFE Linear regression                            Number of obs   =    218,730
Absorbing 2 HDFE groups                           F(   1, 218487) =       9.93
                                                  Prob > F        =     0.0016
                                                  R-squared       =     0.5934
                                                  Adj R-squared   =     0.5929
                                                  Within R-sq.    =     0.0000
                                                  Root MSE        =     0.2005

------------------------------------------------------------------------------
       voted |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
no_dmv_match |  -.0027022   .0008574    -3.15   0.002    -.0043827   -.0010217
-------------+----------------------------------------------------------------
    Absorbed |    F(241, 218487) =   1322.942   0.000             (Joint test)
------------------------------------------------------------------------------

Absorbed degrees of freedom:
---------------------------------------------------------------+
 Absorbed FE |  Num. Coefs.  =   Categories  -   Redundant     | 
-------------+-------------------------------------------------|
          op |          238             238              0     | 
    election |            4               5              1     | 
---------------------------------------------------------------+

. local b5_2 = _b[no_dmv_match]

. local se5_2 = _se[no_dmv_match]

. local n5 = N

. local nclust5 = N_voters

. 
. 
. * match on pre-treatment turnout path and race
. 
. restore

. preserve

. 
. collapse (sum) count (mean) voted, by(outcome_path_pretreat no_dmv_match election race_string)

. 
. *** get N by path by summing together n treated and n control
. sort outcome_path race_string no_dmv_match

. by outcome_path race_string: gen tot_tmp = count[6] if _n==6
(11,833 missing values generated)

. egen tot_treat = sum(tot_tmp), by(outcome_path race_string)

. by outcome_path race_string: replace tot_tmp = count[1] if _n == 1
(1,549 real changes made)

. egen tot = sum(tot_tmp), by(outcome_path race_string)

. // N_voters is the number of voters who enter into the regression
. egen N_voters = sum(tot_tmp)

. // get number of elections
. unique election
Number of unique values of election is  5
Number of records is  12855

. // N is number of voters * number of elections
. gen long N = N_voters * r(unique)

. drop tot_tmp

. gen tot_control = tot - tot_treat

. 
. *** get weights for fw based on total n per stratum
. *** each stratum has 10 obs
. *** fw requires integers so need to round
. gen tot2 = round(tot/10)

. gen tot_treat2 = round(tot_treat/10)

. egen op = group(outcome_path race_string)

. 
. reghdfe voted no_dmv_match [fw=tot_treat2], a(op election)
weight tot_treat2 can only contain strictly positive integers, but 6845 zero values were found (will be dropped)
(converged in 3 iterations)

HDFE Linear regression                            Number of obs   =    218,570
Absorbing 2 HDFE groups                           F(   1, 217964) =      11.65
                                                  Prob > F        =     0.0006
                                                  R-squared       =     0.5955
                                                  Adj R-squared   =     0.5943
                                                  Within R-sq.    =     0.0001
                                                  Root MSE        =     0.2002

------------------------------------------------------------------------------
       voted |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
no_dmv_match |   -.002923   .0008564    -3.41   0.001    -.0046015   -.0012446
-------------+----------------------------------------------------------------
    Absorbed |    F(604, 217964) =    531.138   0.000             (Joint test)
------------------------------------------------------------------------------

Absorbed degrees of freedom:
---------------------------------------------------------------+
 Absorbed FE |  Num. Coefs.  =   Categories  -   Redundant     | 
-------------+-------------------------------------------------|
          op |          601             601              0     | 
    election |            4               5              1     | 
---------------------------------------------------------------+

. local b6 = _b[no_dmv_match]

. local se6 = _se[no_dmv_match]

. local b6_2 = _b[no_dmv_match]

. local se6_2 = _se[no_dmv_match]

. local n6 = N

. local nclust6 = N_voters

. 
. restore

. 
. collapse (sum) count (mean) voted, by(outcome_path_pretreat no_dmv_match election race_string age_bin)

. 
. // drop if age is missing
. drop if age_bin == .
(1,755 observations deleted)

. 
. *** get N by path by summing together n treated and n control
. sort outcome_path race_string age_bin no_dmv_match election

. by outcome_path race_string age_bin: gen tot_tmp = count[6] if _n==6
(67,314 missing values generated)

. egen tot_treat = sum(tot_tmp), by(outcome_path race_string age_bin)

. by outcome_path race_string age_bin: replace tot_tmp = count[1] if _n == 1
(10,022 real changes made)

. egen tot = sum(tot_tmp), by(outcome_path race_string age_bin)

. // N_voters is the number of voters who enter into the regression
. egen N_voters = sum(tot_tmp)

. // get number of elections
. unique election
Number of unique values of election is  5
Number of records is  71615

. // N is number of voters * number of elections
. gen long N = N_voters * r(unique)

. drop tot_tmp

. gen tot_control = tot - tot_treat

. 
. *** get weights for fw based on total n per stratum
. *** each stratum has 10 obs
. *** fw requires integers so need to round
. gen tot2 = round(tot/10)

. gen tot_treat2 = round(tot_treat/10)

. egen op = group(outcome_path race_string age_bin)

. 
. reghdfe voted no_dmv_match [fw=tot_treat2], a(op election)
weight tot_treat2 can only contain strictly positive integers, but 53965 zero values were found (will be dropped)
(converged in 3 iterations)

HDFE Linear regression                            Number of obs   =    209,790
Absorbing 2 HDFE groups                           F(   1, 208020) =       2.77
                                                  Prob > F        =     0.0958
                                                  R-squared       =     0.5969
                                                  Adj R-squared   =     0.5935
                                                  Within R-sq.    =     0.0000
                                                  Root MSE        =     0.1967

------------------------------------------------------------------------------
       voted |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
no_dmv_match |   -.001431   .0008591    -1.67   0.096    -.0031148    .0002528
-------------+----------------------------------------------------------------
    Absorbed |   F(1768, 208020) =    174.217   0.000             (Joint test)
------------------------------------------------------------------------------

Absorbed degrees of freedom:
---------------------------------------------------------------+
 Absorbed FE |  Num. Coefs.  =   Categories  -   Redundant     | 
-------------+-------------------------------------------------|
          op |         1765            1765              0     | 
    election |            4               5              1     | 
---------------------------------------------------------------+

. local b7_2 = _b[no_dmv_match]

. local se7_2 = _se[no_dmv_match]

. local n7 = N 

. local nclust7 = N_voters

. 
. log close
      name:  <unnamed>
       log:  /Users/jesse/Dropbox/voter_id/Replication/table4.log
  log type:  text
 closed on:  17 Aug 2020, 12:12:46
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
